package com.example.doctorstation.POJOController;

import com.example.doctorstation.Config.MyResponse;
import com.example.doctorstation.POJOData.*;
import com.example.doctorstation.POJOMapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class InHospitalInfoController {
    @Resource
    PatientAdviceMapper patientAdviceMapper;
    @Resource
    PatientDiagnoseMapper patientDiagnoseMapper;
    @Resource
    InHospitalInfoMapper inHospitalInfoMapper;

    @PostMapping(value="/inhospitalinfo")
    public MyResponse getAllBedsByDepartName(InHospitalInfo info) {
        try {
            return new MyResponse(inHospitalInfoMapper.InsertInHospitalInfo(info), "已成功登记入院信息！", "登记入院信息失败！");
        } catch (Throwable e) {
            e.printStackTrace();
            return new MyResponse();
        }
    }

    @PutMapping(value="/outhospital")
    public MyResponse isHavingAdviceAndDiagnose(@RequestBody InHospitalInfo info ) {
        try {
            //出院前判断是否录入了医嘱和诊断
            Integer result1 =  patientAdviceMapper.getPatientAdviceCount(info.getInHospitalInfoID());
            Integer result2 =  patientDiagnoseMapper.getPatientDiagnoseCount(info.getInHospitalInfoID());
            if(result1==0)
                return new MyResponse(new Object(), "该病人此次住院没有录入医嘱", "该病人此次住院没有录入医嘱");
            if(result2==0)
                return new MyResponse(new Object(), "该病人此次住院没有录入诊断", "该病人此次住院没有录入诊断");
            //出院
            return new MyResponse(inHospitalInfoMapper.UpdateinflagID(info.getInHospitalInfoID()), "该病人的出院手续处理完成", "出院失败");
        } catch (Throwable e) {
            e.printStackTrace();
            return MyResponse.error(e.getMessage());
        }
    }

}
